package com.ruoyi.puyu.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.puyu.domain.PuyuMatchSchedule;
import com.ruoyi.puyu.service.IPuyuMatchScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 赛程Controller
 * 
 * @author wusongwen
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/puyu/schedule")
public class PuyuMatchScheduleController extends BaseController
{
    @Autowired
    private IPuyuMatchScheduleService puyuMatchScheduleService;

    /**
     * 查询赛程列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PuyuMatchSchedule puyuMatchSchedule)
    {
        startPage();
        List<PuyuMatchSchedule> list = puyuMatchScheduleService.selectPuyuMatchScheduleList(puyuMatchSchedule);
        return getDataTable(list);
    }
    @GetMapping("/sort")
    public TableDataInfo sort(PuyuMatchSchedule puyuMatchSchedule)
    {
        puyuMatchSchedule.setStatus("0");
        startPage();
        List<PuyuMatchSchedule> list = puyuMatchScheduleService.selectPuyuMatchScheduleList(puyuMatchSchedule);
        return getDataTable(list);
    }

    /**
     * 导出赛程列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:export')")
    @Log(title = "赛程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PuyuMatchSchedule puyuMatchSchedule)
    {
        List<PuyuMatchSchedule> list = puyuMatchScheduleService.selectPuyuMatchScheduleList(puyuMatchSchedule);
        ExcelUtil<PuyuMatchSchedule> util = new ExcelUtil<PuyuMatchSchedule>(PuyuMatchSchedule.class);
        util.exportExcel(response, list, "赛程数据");
    }

    /**
     * 获取赛程详细信息
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(puyuMatchScheduleService.selectPuyuMatchScheduleByScheduleId(scheduleId));
    }

    @GetMapping(value = "/match/{scheduleId}")
    public AjaxResult match(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(puyuMatchScheduleService.selectPuyuMatchScheduleByScheduleId(scheduleId));
    }

    @GetMapping(value = "/match/{scheduleId}/navigation")
    public AjaxResult matchNavigation(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(puyuMatchScheduleService.getNavigation(scheduleId));
    }

    /**
     * 新增赛程
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:add')")
    @Log(title = "赛程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PuyuMatchSchedule puyuMatchSchedule)
    {
        return toAjax(puyuMatchScheduleService.insertPuyuMatchSchedule(puyuMatchSchedule));
    }

    /**
     * 修改赛程
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:edit')")
    @Log(title = "赛程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PuyuMatchSchedule puyuMatchSchedule)
    {
        return toAjax(puyuMatchScheduleService.updatePuyuMatchSchedule(puyuMatchSchedule));
    }

    /**
     * 删除赛程
     */
    @PreAuthorize("@ss.hasPermi('puyu:schedule:remove')")
    @Log(title = "赛程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(puyuMatchScheduleService.deletePuyuMatchScheduleByScheduleIds(scheduleIds));
    }
}
